package com.zegome.game.gomestory.main.scene.play.board;

import java.util.Random;
import java.util.Vector;

public class SearchEat {
	private Board board;	
	public SearchEat(Board board){
		this.board = board;
	}	
	
	public int[] search(){
		int[] result = null;
//		Vector<Possition> possitionAble = new Vector<Possition>();
//		Vector<Possition> temp= new Vector<Possition>();
//		for(int i=1;i<=board.dataMap.mapRow;i++){
//			for(int j=1;j<=board.dataMap.mapCol;j++){						
//				if(board.dataMap.map[i][j].type != -1){
//					possitionAble.add(new Possition(i, j));
//				}
//			}
//		}
//		if(possitionAble.size()<2)
//			return result;
//		Random rand = new Random();
//		int pos, pos2;
//		boolean isFind = false;
//		while (isFind == false && possitionAble.size()>=2) {						
//			pos = rand.nextInt(possitionAble.size());	
//			temp.removeAllElements();
//			temp.addAll(possitionAble);
//			pos2 = pos;
//			
//			boolean isCatch = false;
//			while (isCatch == false&&temp.size()>1) {
//				temp.removeElementAt(pos2);
//				pos2 = rand.nextInt(temp.size());
//				if(board.dataMap.map[temp.elementAt(pos2).row][temp.elementAt(pos2).col].type == 
//				   board.dataMap.map[possitionAble.elementAt(pos).row][possitionAble.elementAt(pos).col].type)					
//				{	
//					if(board.checkEat.checkEat(temp.elementAt(pos2).row, temp.elementAt(pos2).col, possitionAble.elementAt(pos).row, possitionAble.elementAt(pos).col, false)){
//						System.out.println(temp.elementAt(pos2).row+":"+temp.elementAt(pos2).col
//							+"--------"+possitionAble.elementAt(pos).row+":"+possitionAble.elementAt(pos).col);
//						result = new int[4];
//						result[0] = possitionAble.elementAt(pos).row; 
//						result[1] = possitionAble.elementAt(pos).col;
//						result[2] = temp.elementAt(pos2).row;
//						result[3] = temp.elementAt(pos2).col;
//						isCatch = true;
//						isFind = true;
//						break;
//					}
//				}
//
//			}
//			if(isFind){
//				break;
//			}
//			possitionAble.removeElementAt(pos);
//		}
		

			int i,j,r1,c1,r2,c2;
			for( i=1; i<=board.dataMap.mapRow*board.dataMap.mapCol-1;i++){
				for( j=i+1; j<=board.dataMap.mapRow*board.dataMap.mapCol;j++){
					r1 = (i-1)/board.dataMap.mapCol+1;
					c1 = i-(r1-1)*board.dataMap.mapCol;
					r2 = (j-1)/board.dataMap.mapCol+1;
					c2 = j-(r2-1)*board.dataMap.mapCol;
					if(board.dataMap.map[r2][c2].type!=-1&&board.dataMap.map[r1][c1].type==board.dataMap.map[r2][c2].type){
						if(board.checkEat.checkEat(r1, c1, r2, c2,false)){
							result = new int[4];
							result[0] = r1;
							result[1] = c1;
							result[2] = r2;
							result[3] = c2;
							return result;
						}
					}
				}
			}	
		return result;
	}	
}
